The present invention relates to a portable medium, such as an IC card, for incorporating, e.g., a CPU, data memory, and the like.
In recent years, an IC card has been developed as a memory card for storing data and is commercially available. The IC card incorporates a CPU (Central Processing Unit), a data memory comprising an EPROM, and the like. However, since the conventional IC card adopts the EPROM as a memory element, data once written in the memory cannot be rewritten or erased. For this reason, unnecessary data cannot be erased. In order to solve this, unnecessary data is made invalid so as not to be accessed externally.
Another conventional IC card adopts an electrically rewritable EEPROM as a memory element to allow unnecessary data to be erased. However, if invalid data is simply selected and erased, both valid data and erased areas are present in the memory. When new data is stored, data indicating which erased area is used must be stored. More specifically, the memory access sequence may be changed.
In a system using an IC card of this type, data exchange with the IC card is performed using a card reader/writer. When the IC card receives instruction data with a function code, it executes a function and outputs the execution result to the card reader/writer as response data. When a data string input to the IC card is written in a data memory, the data string is stored in units of blocks, and read/write access is made taking in units of blocks. However, during storage of a series of data blocks, when a block cannot be constituted for some reason, if the uncompleted storage data is left uncorrected, another data string is written thereafter, and the uncompleted storage data cannot be recognized as a correct block.